from envs.game_env_multiRound import BFTblockchainModel
import matplotlib.pyplot as plt
import matplotlib.font_manager as font_manager
import numpy as np
if __name__ == '__main__':
# when threshold is smaller than 0.5
# both H and B are larger or equal to threshold, H larger than rate, then Honest Eq.
model = BFTblockchainModel(n = 512, R = 100, c_check = 5, c_send = 5, kappa = 1, threshold = 0.4, initial_h = 0.55)
ax, fig = plt.subplots(figsize=(200, 100))
model.setup();
plt.scatter([model.counter for _ in range(100)], [0 for i in range(100)], color = 'black')
p=[0.55]
c=[0]
rounds_h = []
rounds_b = []
rewards_h = []
rewards_b = []
while model.terminate == False:
model.step()
r_honest = model.r_honest_at_round
r_byzantine = model.r_byzantine_at_round
rewards_h += r_honest
rewards_b += r_byzantine
rounds_h += [model.counter for _ in range(len(r_honest))]
rounds_b += [model.counter for _ in range(len(r_byzantine))]
p.append(model.proportion_of_honest)
c.append(model.counter)
rewards_h = np.array(rewards_h) / 100
rewards_b = np.array(rewards_b) / 100
plt.scatter(rounds_h, rewards_h, color = 'blue', label = 'rewards of honest', s=5000)
plt.scatter(rounds_b, rewards_b, color = 'red', label = 'rewards of byzantine', s=5000)
plt.plot(c, p, color = 'green', label = 'proportion of honest', linewidth=50)
font = font_manager.FontProperties(family='serif',
style='normal', size=200)
ax.legend(loc = 'upper right', prop=font)
plt.xlabel('Number of Rounds', fontname='serif', fontsize = 200)
plt.ylabel('Proportion of Honest', fontname='serif', fontsize = 200)
plt.xticks(fontsize=200)
plt.yticks(fontsize=200)
plt.grid(True)
plt.savefig('test1.png')
The total rewards of Honest at round 1 is: 13015.919999999951 The total rewards of Byzantine at round 1 is: 8829.975000000037 tmp: 0.5958062143940523 total_r_honest: 13015.919999999951 total_r_byzantine: 8829.975000000037 The probability of being honest: 0.5521341385002638 The proportion of honest: 0.552734375 The total rewards of Honest at round 2 is: 13325.903999999957 The total rewards of Byzantine at round 2 is: 8579.485000000022 tmp: 0.6083390712668909 total_r_honest: 13325.903999999957 total_r_byzantine: 8579.485000000022 The probability of being honest: 0.5590533342695998 The proportion of honest: 0.546875 The total rewards of Honest at round 3 is: 13883.520000000066 The total rewards of Byzantine at round 3 is: 8118.839999999978 tmp: 0.6310014016678228 total_r_honest: 13883.520000000066 total_r_byzantine: 8118.839999999978 The probability of being honest: 0.5715637320268276 The proportion of honest: 0.580078125 The total rewards of Honest at round 4 is: 14355.791999999927 The total rewards of Byzantine at round 4 is: 7789.449999999957 tmp: 0.6482562710310414 total_r_honest: 14355.791999999927 total_r_byzantine: 7789.449999999957 The probability of being honest: 0.5813498450959546 The proportion of honest: 0.591796875 The total rewards of Honest at round 5 is: 15692.975999999948 The total rewards of Byzantine at round 5 is: 6857.290000000028 tmp: 0.6959109041108413 total_r_honest: 15692.975999999948 total_r_byzantine: 6857.290000000028 The probability of being honest: 0.6086841114946868 The proportion of honest: 0.59375 The total rewards of Honest at round 6 is: 14694.143999999922 The total rewards of Byzantine at round 6 is: 7535.83999999996 tmp: 0.661005603962648 total_r_honest: 14694.143999999922 total_r_byzantine: 7535.83999999996 The probability of being honest: 0.5885356692503043 The proportion of honest: 0.578125 The total rewards of Honest at round 7 is: 15046.272000000068 The total rewards of Byzantine at round 7 is: 7292.1600000000335 tmp: 0.6735598989221804 total_r_honest: 15046.272000000068 total_r_byzantine: 7292.1600000000335 The probability of being honest: 0.5957302474062465 The proportion of honest: 0.578125 The total rewards of Honest at round 8 is: 13966.463999999936 The total rewards of Byzantine at round 8 is: 8071.91999999998 tmp: 0.6337335804657904 total_r_honest: 13966.463999999936 total_r_byzantine: 8071.91999999998 The probability of being honest: 0.5731530338648418 The proportion of honest: 0.587890625 The total rewards of Honest at round 9 is: 15936.143999999957 The total rewards of Byzantine at round 9 is: 6682.370000000013 tmp: 0.7045619354127322 total_r_honest: 15936.143999999957 total_r_byzantine: 6682.370000000013 The probability of being honest: 0.6136518163761492 The proportion of honest: 0.62109375 The total rewards of Honest at round 10 is: 16536.0 The total rewards of Byzantine at round 10 is: 0.0 tmp: 1.0 total_r_honest: 16536.0 total_r_byzantine: 0.0 The probability of being honest: 0.6956778818151877 The proportion of honest: 0.708984375 TERMINATED! The final proportion of honest is: 1 The total rounds of game is: 10
from envs.game_env_multiRound import BFTblockchainModel
import matplotlib.pyplot as plt
import matplotlib.font_manager as font_manager
import numpy as np
if __name__ == '__main__':
# when threshold is smaller than 0.5
# both H and B are larger larger or equal to threshold, H smaller than rate, then Byzantine Eq.
model = BFTblockchainModel(n = 512, R = 100, c_check = 5, c_send = 5, kappa = 1, threshold = 0.4, initial_h = 0.5)
ax, fig = plt.subplots(figsize=(200, 100))
model.setup();
plt.scatter([model.counter for _ in range(100)], [0 for i in range(100)], color = 'black')
p=[0.5]
c=[0]
rounds_h = []
rounds_b = []
rewards_h = []
rewards_b = []
while model.terminate == False:
model.step()
r_honest = model.r_honest_at_round
r_byzantine = model.r_byzantine_at_round
rewards_h += r_honest
rewards_b += r_byzantine
rounds_h += [model.counter for _ in range(len(r_honest))]
rounds_b += [model.counter for _ in range(len(r_byzantine))]
p.append(model.proportion_of_honest)
c.append(model.counter)
rewards_h = np.array(rewards_h) / 100
rewards_b = np.array(rewards_b) / 100
plt.scatter(rounds_h, rewards_h, color = 'blue', label = 'rewards of honest', s=5000)
plt.scatter(rounds_b, rewards_b, color = 'red', label = 'rewards of byzantine', s=5000)
plt.plot(c, p, color = 'green', label = 'proportion of honest', linewidth=50)
font = font_manager.FontProperties(family='serif',
style='normal', size=200)
ax.legend(loc = 'upper right', prop=font)
plt.xlabel('Number of Rounds', fontname='serif', fontsize = 200)
plt.ylabel('Proportion of Honest', fontname='serif', fontsize = 200)
plt.xticks(fontsize=200)
plt.yticks(fontsize=200)
plt.grid(True)
plt.savefig('test2.png')
The total rewards of Honest at round 1 is: 9844.607999999982 The total rewards of Byzantine at round 1 is: 11821.920000000038 tmp: 0.45436943104128047 total_r_honest: 9844.607999999982 total_r_byzantine: 11821.920000000038 The probability of being honest: 0.4753037126870858 The proportion of honest: 0.484375 The total rewards of Honest at round 2 is: 10154.112000000016 The total rewards of Byzantine at round 2 is: 11495.880000000016 tmp: 0.4690122749237044 total_r_honest: 10154.112000000016 total_r_byzantine: 11495.880000000016 The probability of being honest: 0.4832341879002197 The proportion of honest: 0.48828125 The total rewards of Honest at round 3 is: 10667.999999999989 The total rewards of Byzantine at round 3 is: 10960.769999999948 tmp: 0.4932319313580948 total_r_honest: 10667.999999999989 total_r_byzantine: 10960.769999999948 The probability of being honest: 0.49634044034903685 The proportion of honest: 0.513671875 The total rewards of Honest at round 4 is: 10541.039999999985 The total rewards of Byzantine at round 4 is: 11055.59999999995 tmp: 0.48808703576111917 total_r_honest: 10541.039999999985 total_r_byzantine: 11055.59999999995 The probability of being honest: 0.4935683547709885 The proportion of honest: 0.525390625 The total rewards of Honest at round 5 is: 12150.191999999945 The total rewards of Byzantine at round 5 is: 9565.69499999996 tmp: 0.559507055825074 total_r_honest: 12150.191999999945 total_r_byzantine: 9565.69499999996 The probability of being honest: 0.5322613304938398 The proportion of honest: 0.529296875 The total rewards of Honest at round 6 is: 11616.14399999993 The total rewards of Byzantine at round 6 is: 10036.44500000006 tmp: 0.5364782936580903 total_r_honest: 11616.14399999993 total_r_byzantine: 10036.44500000006 The probability of being honest: 0.5197359781238771 The proportion of honest: 0.486328125 The total rewards of Honest at round 7 is: 10171.151999999991 The total rewards of Byzantine at round 7 is: 11477.319999999983 tmp: 0.46983232811997094 total_r_honest: 10171.151999999991 total_r_byzantine: 11477.319999999983 The probability of being honest: 0.48367870070394325 The proportion of honest: 0.466796875 The total rewards of Honest at round 8 is: 8844.911999999968 The total rewards of Byzantine at round 8 is: 12951.12000000002 tmp: 0.40580377198932227 total_r_honest: 8844.911999999968 total_r_byzantine: 12951.12000000002 The probability of being honest: 0.4488519415189959 The proportion of honest: 0.443359375 The total rewards of Honest at round 9 is: 8923.82399999998 The total rewards of Byzantine at round 9 is: 12870.599999999968 tmp: 0.4094544549560017 total_r_honest: 8923.82399999998 total_r_byzantine: 12870.599999999968 The probability of being honest: 0.4508247807680204 The proportion of honest: 0.4453125 The total rewards of Honest at round 10 is: 8043.839999999982 The total rewards of Byzantine at round 10 is: 13958.599999999933 tmp: 0.3655885438160501 total_r_honest: 8043.839999999982 total_r_byzantine: 13958.599999999933 The probability of being honest: 0.42659969360142647 The proportion of honest: 0.400390625 The total rewards of Honest at round 11 is: 6740.400000000019 The total rewards of Byzantine at round 11 is: 15818.174999999923 tmp: 0.2987954691287032 total_r_honest: 6740.400000000019 total_r_byzantine: 15818.174999999923 The probability of being honest: 0.3884365796897125 The proportion of honest: 0.400390625 The total rewards of Honest at round 12 is: 7409.520000000009 The total rewards of Byzantine at round 12 is: 14826.56500000002 tmp: 0.3332205287036814 total_r_honest: 7409.520000000009 total_r_byzantine: 14826.56500000002 The probability of being honest: 0.408335103983819 The proportion of honest: 0.3984375 The total rewards of Honest at round 13 is: -117.70799999999969 The total rewards of Byzantine at round 13 is: 15343.020000000044 tmp: -0.007731073097221216 total_r_honest: -117.70799999999969 total_r_byzantine: 15343.020000000044 The probability of being honest: 0.3158226382844817 The proportion of honest: 0.318359375 TERMINATED! The final proportion of honest is: 0 The total rounds of game is: 13
from envs.game_env_multiRound import BFTblockchainModel
import matplotlib.pyplot as plt
import matplotlib.font_manager as font_manager
import numpy as np
if __name__ == '__main__':
# when threshold is 0.5
# both H and B are 0.5, then Byzantine Eq. (because H is smaller than rate)
model = BFTblockchainModel(n = 512, R = 100, c_check = 5, c_send = 5, kappa = 1, threshold = 0.5, initial_h = 0.5)
ax, fig = plt.subplots(figsize=(200, 100))
model.setup();
plt.scatter([model.counter for _ in range(100)], [0 for i in range(100)], color = 'black')
p=[0.5]
c=[0]
rounds_h = []
rounds_b = []
rewards_h = []
rewards_b = []
while model.terminate == False:
model.step()
r_honest = model.r_honest_at_round
r_byzantine = model.r_byzantine_at_round
rewards_h += r_honest
rewards_b += r_byzantine
rounds_h += [model.counter for _ in range(len(r_honest))]
rounds_b += [model.counter for _ in range(len(r_byzantine))]
p.append(model.proportion_of_honest)
c.append(model.counter)
rewards_h = np.array(rewards_h) / 100
rewards_b = np.array(rewards_b) / 100
plt.scatter(rounds_h, rewards_h, color = 'blue', label = 'rewards of honest', s=5000)
plt.scatter(rounds_b, rewards_b, color = 'red', label = 'rewards of byzantine', s=5000)
plt.plot(c, p, color = 'green', label = 'proportion of honest', linewidth=50)
font = font_manager.FontProperties(family='serif',
style='normal', size=200)
ax.legend(loc = 'upper right', prop=font)
plt.xlabel('Number of Rounds', fontname='serif', fontsize = 200)
plt.ylabel('Proportion of Honest', fontname='serif', fontsize = 200)
plt.xticks(fontsize=200)
plt.yticks(fontsize=200)
plt.grid(True)
plt.savefig('test3.png')
The total rewards of Honest at round 1 is: 9844.607999999982 The total rewards of Byzantine at round 1 is: 11821.920000000038 tmp: 0.45436943104128047 total_r_honest: 9844.607999999982 total_r_byzantine: 11821.920000000038 The probability of being honest: 0.4753037126870858 The proportion of honest: 0.484375 The total rewards of Honest at round 2 is: -126.72799999999961 The total rewards of Byzantine at round 2 is: 11495.880000000016 tmp: -0.011146653681822482 total_r_honest: -126.72799999999961 total_r_byzantine: 11495.880000000016 The probability of being honest: 0.3586725301381226 The proportion of honest: 0.388671875 TERMINATED! The final proportion of honest is: 0 The total rounds of game is: 2
from envs.game_env_multiRound import BFTblockchainModel
import matplotlib.pyplot as plt
import matplotlib.font_manager as font_manager
import numpy as np
if __name__ == '__main__':
# when threshold is 0.5
# H larger than 0.5, then Honest Eq.
model = BFTblockchainModel(n = 512, R = 100, c_check = 5, c_send = 5, kappa = 1, threshold = 0.5, initial_h = 0.51)
ax, fig = plt.subplots(figsize=(200, 100))
model.setup();
plt.scatter([model.counter for _ in range(100)], [0 for i in range(100)], color = 'black')
p=[0.51]
c=[0]
rounds_h = []
rounds_b = []
rewards_h = []
rewards_b = []
while model.terminate == False:
model.step()
r_honest = model.r_honest_at_round
r_byzantine = model.r_byzantine_at_round
rewards_h += r_honest
rewards_b += r_byzantine
rounds_h += [model.counter for _ in range(len(r_honest))]
rounds_b += [model.counter for _ in range(len(r_byzantine))]
p.append(model.proportion_of_honest)
c.append(model.counter)
rewards_h = np.array(rewards_h) / 100
rewards_b = np.array(rewards_b) / 100
plt.scatter(rounds_h, rewards_h, color = 'blue', label = 'rewards of honest', s=5000)
plt.scatter(rounds_b, rewards_b, color = 'red', label = 'rewards of byzantine', s=5000)
plt.plot(c, p, color = 'green', label = 'proportion of honest', linewidth=50)
font = font_manager.FontProperties(family='serif',
style='normal', size=200)
ax.legend(loc = 'upper right', prop=font)
plt.xlabel('Number of Rounds', fontname='serif', fontsize = 200)
plt.ylabel('Proportion of Honest', fontname='serif', fontsize = 200)
plt.xticks(fontsize=200)
plt.yticks(fontsize=200)
plt.grid(True)
plt.savefig('test4.png')
The total rewards of Honest at round 1 is: 10529.569999999985 The total rewards of Byzantine at round 1 is: 0.0 tmp: 1.0 total_r_honest: 10529.569999999985 total_r_byzantine: 0.0 The probability of being honest: 0.628661404171865 The proportion of honest: 0.630859375 TERMINATED! The final proportion of honest is: 1 The total rounds of game is: 1
from envs.game_env_multiRound import BFTblockchainModel
import matplotlib.pyplot as plt
import matplotlib.font_manager as font_manager
import numpy as np
if __name__ == '__main__':
# when threshold is 0.5
# B larger than 0.5, then Byzantine Eq.
model = BFTblockchainModel(n = 100, R = 100, c_check = 5, c_send = 5, kappa = 1, threshold = 0.5, initial_h = 0.48)
ax, fig = plt.subplots(figsize=(200, 100))
model.setup();
plt.scatter([model.counter for _ in range(100)], [0 for i in range(100)], color = 'black')
p=[0.48]
c=[0]
rounds_h = []
rounds_b = []
rewards_h = []
rewards_b = []
while model.terminate == False:
model.step()
r_honest = model.r_honest_at_round
r_byzantine = model.r_byzantine_at_round
rewards_h += r_honest
rewards_b += r_byzantine
rounds_h += [model.counter for _ in range(len(r_honest))]
rounds_b += [model.counter for _ in range(len(r_byzantine))]
p.append(model.proportion_of_honest)
c.append(model.counter)
rewards_h = np.array(rewards_h) / 100
rewards_b = np.array(rewards_b) / 100
plt.scatter(rounds_h, rewards_h, color = 'blue', label = 'rewards of honest', s=5000)
plt.scatter(rounds_b, rewards_b, color = 'red', label = 'rewards of byzantine', s=5000)
plt.plot(c, p, color = 'green', label = 'proportion of honest', linewidth=50)
font = font_manager.FontProperties(family='serif',
style='normal', size=200)
ax.legend(loc = 'upper right', prop=font)
plt.xlabel('Number of Rounds', fontname='serif', fontsize = 200)
plt.ylabel('Proportion of Honest', fontname='serif', fontsize = 200)
plt.xticks(fontsize=200)
plt.yticks(fontsize=200)
plt.grid(True)
plt.savefig('test5.png')
The total rewards of Honest at round 1 is: -24.39999999999998 The total rewards of Byzantine at round 1 is: 2067.9999999999977 tmp: -0.01193971422979057 total_r_honest: -24.39999999999998 total_r_byzantine: 2067.9999999999977 The probability of being honest: 0.47386883020758874 The proportion of honest: 0.43999999999999995 TERMINATED! The final proportion of honest is: 0 The total rounds of game is: 1
from envs.game_env_multiRound import BFTblockchainModel
import matplotlib.pyplot as plt
import matplotlib.font_manager as font_manager
import numpy as np
if __name__ == '__main__':
# when threshold is larger than 0.5
# H larger than threshold, then Honest Eq.
model = BFTblockchainModel(n = 512, R = 100, c_check = 5, c_send = 5, kappa = 1, threshold = 0.55, initial_h = 0.55)
ax, fig = plt.subplots(figsize=(200, 100))
model.setup();
plt.scatter([model.counter for _ in range(100)], [0 for i in range(100)], color = 'black')
p=[0.55]
c=[0]
rounds_h = []
rounds_b = []
rewards_h = []
rewards_b = []
while model.terminate == False:
model.step()
r_honest = model.r_honest_at_round
r_byzantine = model.r_byzantine_at_round
rewards_h += r_honest
rewards_b += r_byzantine
rounds_h += [model.counter for _ in range(len(r_honest))]
rounds_b += [model.counter for _ in range(len(r_byzantine))]
p.append(model.proportion_of_honest)
c.append(model.counter)
rewards_h = np.array(rewards_h) / 100
rewards_b = np.array(rewards_b) / 100
plt.scatter(rounds_h, rewards_h, color = 'blue', label = 'rewards of honest', s=5000)
plt.scatter(rounds_b, rewards_b, color = 'red', label = 'rewards of byzantine', s=5000)
plt.plot(c, p, color = 'green', label = 'proportion of honest', linewidth=50)
font = font_manager.FontProperties(family='serif',
style='normal', size=200)
ax.legend(loc = 'upper right', prop=font)
plt.xlabel('Number of Rounds', fontname='serif', fontsize = 200)
plt.ylabel('Proportion of Honest', fontname='serif', fontsize = 200)
plt.xticks(fontsize=200)
plt.yticks(fontsize=200)
plt.grid(True)
plt.savefig('test6.png')
The total rewards of Honest at round 1 is: 13143.774999999936 The total rewards of Byzantine at round 1 is: 0.0 tmp: 1.0 total_r_honest: 13143.774999999936 total_r_byzantine: 0.0 The probability of being honest: 0.6586285976849072 The proportion of honest: 0.66015625 TERMINATED! The final proportion of honest is: 1 The total rounds of game is: 1
from envs.game_env_multiRound import BFTblockchainModel
import matplotlib.pyplot as plt
import matplotlib.font_manager as font_manager
import numpy as np
if __name__ == '__main__':
# when threshold is larger than 0.5
# B larger than threshold, then Byzantine Eq.
model = BFTblockchainModel(n = 512, R = 100, c_check = 5, c_send = 5, kappa = 1, threshold = 0.55, initial_h = 0.45)
ax, fig = plt.subplots(figsize=(200, 100))
model.setup();
plt.scatter([model.counter for _ in range(100)], [0 for i in range(100)], color = 'black')
p=[0.45]
c=[0]
rounds_h = []
rounds_b = []
rewards_h = []
rewards_b = []
while model.terminate == False:
model.step()
r_honest = model.r_honest_at_round
r_byzantine = model.r_byzantine_at_round
rewards_h += r_honest
rewards_b += r_byzantine
rounds_h += [model.counter for _ in range(len(r_honest))]
rounds_b += [model.counter for _ in range(len(r_byzantine))]
p.append(model.proportion_of_honest)
c.append(model.counter)
rewards_h = np.array(rewards_h) / 100
rewards_b = np.array(rewards_b) / 100
plt.scatter(rounds_h, rewards_h, color = 'blue', label = 'rewards of honest', s=5000)
plt.scatter(rounds_b, rewards_b, color = 'red', label = 'rewards of byzantine', s=5000)
plt.plot(c, p, color = 'green', label = 'proportion of honest', linewidth=50)
font = font_manager.FontProperties(family='serif',
style='normal', size=200)
ax.legend(loc = 'upper right', prop=font)
plt.xlabel('Number of Rounds', fontname='serif', fontsize = 200)
plt.ylabel('Proportion of Honest', fontname='serif', fontsize = 200)
plt.xticks(fontsize=200)
plt.yticks(fontsize=200)
plt.grid(True)
plt.savefig('test7.png')
The total rewards of Honest at round 1 is: -127.9080000000008 The total rewards of Byzantine at round 1 is: 13715.780000000019 tmp: -0.009413394533007128 total_r_honest: -127.9080000000008 total_r_byzantine: 13715.780000000019 The probability of being honest: 0.33354731888920264 The proportion of honest: 0.33984375 TERMINATED! The final proportion of honest is: 0 The total rounds of game is: 1